import os
import sys

# 请在此输入您的代码

n, m = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]

ans = [[0] * m for _ in range(n)]
# print(ans)

# print(a)

for i in range(n):
    for j in range(m):
        tot, cnt = 0, 0
        # for every pos, we do with 9 dir(self- including)
        for delta_x in [-1, 0, 1]:
            for delta_y in [-1, 0, 1]:
                x = i + delta_x
                y = j + delta_y

                if 0 <= x < n and 0 <= y < m:
                    tot += a[x][y]
                    cnt += 1
        ans[i][j] = tot // cnt

for i in range(n):
    print(*ans[i])
